package com.guan.ordering_sys.exception;


import com.guan.ordering_sys.common.ResultApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

/**
 * 全局异常处理处理类
 *
 * @author olay
 * @version 1.0
 * @date 6/4/2021 9:39 AM
 */
@ControllerAdvice
@RestController
@Slf4j
public class ControllerExceptionHandler {
    @ExceptionHandler({BaseException.class}) // 当发生 BaseException 类(及其子类)的异常时，进入该方法
    public ResultApi springBootExceptionHandler(BaseException e) {
        return ResultApi.errorNotData(e.getStateCode());
    }

}
